﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GameSchool.Models;

namespace GameSchool.Controllers
{
    public class LevelController : Controller
    {
		GameSchoolRepository repository = new GameSchoolRepository();
        //
        // GET: /Level/
        #region Views

        //For teachers
        //Displays form with the fields filled in with data from the database
        public ActionResult LevelEdit(int CID)
        {
            EditLevelViewModel vm = new EditLevelViewModel();
            vm.itemList = new List<EditLevelViewModel.LevelAndTasksItem>();

            var teacherLogin = repository.GetTeacherLoginRelationship();
            vm.theCourse = repository.GetCourseByID(CID);
            vm.courseID = CID;
            vm.Levels = repository.GetAllLevelsByCourse(vm.theCourse).ToList();
            vm.sidebarCourses = repository.GetCoursesByTeacher(teacherLogin).ToList();
            vm.courseName = vm.theCourse.title;
            vm.teacherName = teacherLogin.name;

            foreach (var item in vm.Levels)
            {
                vm.itemList.Add(new EditLevelViewModel.LevelAndTasksItem 
                {
                    levelID = item.levelID,
                    levelTitle = item.title,
                    levelNumber = item.number,
                    levelXP = item.intLevelXP,
                    assignmentID = repository.GetAssignmentByLevel(item).assignmentID,
                    examID = repository.GetExamByLevel(item).examID,
                    lectureID = repository.GetLectureByLevel(item).lectureID
                });
            }
            
			return View(vm);
        }

        //Used to write data to the database if anything was changed in a level form that already has data in it
        [HttpPost]
		public ActionResult LevelEdit(FormCollection formData, int CID)
        {
            EditLevelViewModel vm = new EditLevelViewModel();
			
			
			return View();
        }

        //For teachers
        public ActionResult CreateLevel()
        {
			return View();
        }

        [HttpPost]
        public ActionResult CreateLevel(FormCollection formData)
        {
            return View();
        }

        //For teachers
        [HttpPost]
        public ActionResult RemoveLevel(int id)
        {
            // TODO if we have time - Ólöf
			return View();
        }

        #endregion

        public Notification GetNotifications(Notification theNotification)
        {
            return theNotification;
        }
    }
}
